/**
 * Created by tangqiaojie <2482366539@qq.com> on 2020/5/12 0012
 */
let viewSbxml_yhs = function(s) {
  var e = mini.get("sbjgcx_grid").getRowByUID(s)
    , a = e.sbzlDm
    , i = Api.yhsUrl
    , t = e.gdsBz
    , n = e.pzxh;
  ("12109" === a || "12107" === a && !e.sbuuid) && (e.sbuuid = "null"),
    i += "?zsxmDm=" + e.zsxmDm + "&sbzlDm=" + a + "&sbuuid=" + e.sbuuid + "&sssqQ=" + e.skssqq + "&sssqZ=" + e.skssqz + "&gdsBz=" + t + "&pzxh=" + n,
  "12107" === a && (i = "/yhs-web/api/sbcx/downloadSbbExcel",
    i += "?sbuuid=" + e.sbuuid + "&zsxmDm=" + e.zsxmDm + "&sbzlDm=" + a + "&sssqQ=" + e.skssqq + "&sssqZ=" + e.skssqz + "&gdsBz=" + t + "&pzxh=" + e.pzxh + "&sbxh=" + e.sbxh),
    console.log(i);
}


const sendSbList=(currentZeroInfo,win)=>{

  let sbAllList=[
    {
      declareName:"一般纳税人增值税申报",
      declareCycle:"month",
      accountBook:"",
      declareTime:"",
      isSuccess:true,
    },
    {
      declareName:"附加税申报月报",
      declareCycle:"month",
      accountBook:"",
      declareTime:"",
      isSuccess:true,
    },
  ];

  sbAllList.forEach((item,index)=>{
    const date=new Date(),year=date.getFullYear(),month=date.getMonth()+1,day=date.getDate();
    if(item.declareCycle==='month'){
      item.accountBook=moment().subtract(1, 'months').format("YYYY-MM");
    }else if(item.declareCycle==='year'){
      item.accountBook=moment().subtract(1, 'years').format("YYYY");
    }
  });

  let backInfo = {
    ...currentZeroInfo,
    recordList: sbAllList,
  };
  // 零申报结束
  window.postMessage(
    {
      event: 'zeroReportBack',
      data: backInfo,
    },
    '*'
  );
};

const getQueryString=(name)=>{
  var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
  var r = location.search.substr(1).match(reg);
  if (r != null) return unescape(decodeURI(r[2])); return null;
}


export {
  viewSbxml_yhs,
  sendSbList,
  getQueryString
}
